import pulp

#初始化问题类
first_lp_problem = pulp.LpProblem("first_lp_problem",pulp.LpMinimize)

# 定义决策变量
x = pulp.LpVariable('x',cat='Continuous')
y = pulp.LpVariable('y',cat='Continuous')

#定义目标函数
first_lp_problem += x-2*y,"z"

# 约束条件
first_lp_problem += y >= 2-2*x
first_lp_problem += 2*y <= x+4
first_lp_problem += y>= 3*x-3

# 打印问题
# print(first_lp_problem)

# 求解
first_lp_problem.solve()

# 查看是否有最优解
# print(pulp.LpStatus[first_lp_problem.status])

# print(len(first_lp_problem.variables()))

#查看最优解
for variable in first_lp_problem.variables():
    print("{} = {}".format(variable.name, variable.varValue))

print(pulp.value(first_lp_problem.objective))  

